package org.game.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.cfg.cache.BuildCfgCache;
import org.game.db.cache.BuildingCache;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import org.game.constant.BuildingConstant;
import org.game.protobuf.s2c.S2CBuildingMsg.WorkLog;
import org.cfg.BuildCfg;
import java.util.List;
import java.sql.SQLException;
import com.google.common.collect.Lists;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import static org.game.db.StaticResource.BuildingResource.*;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.BuildingResource.*;
/**
 * 建筑
 */
public class Building extends BasePojo<Building> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[3];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* 建筑id
	*/
	private int cid;
	
	/**
	* 建筑状态
	*/
	private int state;
	
	/**
	* 当前动作完成时间
	*/
	private java.util.Date finishTime;
	
	/**
	* 下次打工奖励时间
	*/
	private java.util.Date nextRewardTime;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 玩家id
	*/
	private int playerId;
	
	/**
	* 打工精灵id
	*/
	private List roleId;
	
	/**
	* 打工奖励
	*/
	private Map reward;
	
	/**
	* 时间日志
	*/
	private List eventLogs;
	
	/**
	* 是否约会占用
	*/
	private boolean inDating;
	
	
	@Deprecated
	public static Building builder() {
		Building building = new Building();
		return building;
	}
	
	@Deprecated
	public Building() {
		super();
	}
	
	public Building(long id, int cid, int state, java.util.Date finishTime, java.util.Date nextRewardTime, int playerId, List roleId, Map reward, List eventLogs, boolean inDating) {
		super();
		this.id = id;
		this.cid = cid;
		this.state = state;
		this.finishTime = finishTime;
		this.nextRewardTime = nextRewardTime;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.playerId = playerId;
		this.roleId = roleId;
		this.reward = reward;
		this.eventLogs = eventLogs;
		this.inDating = inDating;
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public Building setId(long id) {this.id = id;return this;}
	
	/**
	 * 建筑id
	 */
	public int getCid() {return cid;}
	
	/**
	 * 建筑id
	 */
	public Building setCid(int cid) {this.cid = cid;return this;}
	
	/**
	 * 建筑状态
	 */
	public int getState() {return state;}
	
	/**
	 * 建筑状态
	 */
	public Building setState(int state) {this.state = state;return this;}
	
	/**
	 * 当前动作完成时间
	 */
	public java.util.Date getFinishTime() {return finishTime;}
	
	/**
	 * 当前动作完成时间
	 */
	public Building setFinishTime(java.util.Date finishTime) {this.finishTime = finishTime;return this;}
	
	/**
	 * 下次打工奖励时间
	 */
	public java.util.Date getNextRewardTime() {return nextRewardTime;}
	
	/**
	 * 下次打工奖励时间
	 */
	public Building setNextRewardTime(java.util.Date nextRewardTime) {this.nextRewardTime = nextRewardTime;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Building setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Building setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 玩家id
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家id
	 */
	public Building setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 打工精灵id
	 */
	public List getRoleId() {return roleId;}
	
	/**
	 * 打工精灵id
	 */
	public Building setRoleId(List roleId) {this.roleId = roleId;return this;}
	
	/**
	 * 打工精灵id
	 */
	public byte[] getRoleIdByte() {
		return toBytes(roleId);
	}
	
	/**
	 * 打工精灵id
	 */
	public List initRoleIdByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 打工奖励
	 */
	public Map getReward() {return reward;}
	
	/**
	 * 打工奖励
	 */
	public Building setReward(Map reward) {this.reward = reward;return this;}
	
	/**
	 * 打工奖励
	 */
	public byte[] getRewardByte() {
		return toBytes(reward);
	}
	
	/**
	 * 打工奖励
	 */
	public Map initRewardByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * 时间日志
	 */
	public List getEventLogs() {return eventLogs;}
	
	/**
	 * 时间日志
	 */
	public Building setEventLogs(List eventLogs) {this.eventLogs = eventLogs;return this;}
	
	/**
	 * 时间日志
	 */
	public byte[] getEventLogsByte() {
		return toBytes(eventLogs);
	}
	
	/**
	 * 时间日志
	 */
	public List initEventLogsByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 是否约会占用
	 */
	public boolean isInDating() {return inDating;}
	
	/**
	 * 是否约会占用
	 */
	public Building setInDating(boolean inDating) {this.inDating = inDating;return this;}
	
	
	// 代理
	private org.game.db.proxy.bean.BuildingProxy buildingProxy = new org.game.db.proxy.bean.BuildingProxy().build(this);
	
	public org.game.db.proxy.bean.BuildingProxy getBuildingProxy(){return buildingProxy;}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.cid;
        values[2] = this.state;
        values[3] = this.finishTime;
        values[4] = this.nextRewardTime;
        values[5] = this.createDate;
        values[6] = this.modifiedDate;
        values[7] = this.playerId;
        values[8] = this.roleId;
        values[9] = this.reward;
        values[10] = this.eventLogs;
        values[11] = this.inDating;
        return values;
	}
	
	public Building deepCopy(){
		Building building = null;
		try {
			building = (Building) super.clone();
		    building.setFinishTime(ToolCopy.copyObject(this.finishTime));
		    building.setNextRewardTime(ToolCopy.copyObject(this.nextRewardTime));
		    building.setCreateDate(ToolCopy.copyObject(this.createDate));
		    building.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    building.setRoleId(ToolCopy.copyObject(this.roleId));
		    building.setReward(ToolCopy.copyObject(this.reward));
		    building.setEventLogs(ToolCopy.copyObject(this.eventLogs));
		    // 克隆索引
		    building.indexValues = ArrayUtils.clone(indexValues);
			return building;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return building;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.cid);
        map.put(keys[2], this.state);
        map.put(keys[3], this.finishTime);
        map.put(keys[4], this.nextRewardTime);
        map.put(keys[5], this.createDate);
        map.put(keys[6], this.modifiedDate);
        map.put(keys[7], this.playerId);
        map.put(keys[8], this.roleId);
        map.put(keys[9], this.reward);
        map.put(keys[10], this.eventLogs);
        map.put(keys[11], this.inDating);
        return map;
    }
    
    protected Building createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.cid = (int)map.get(keys[1]);
   		this.state = (int)map.get(keys[2]);
   		this.finishTime = (java.util.Date)map.get(keys[3]);
   		this.nextRewardTime = (java.util.Date)map.get(keys[4]);
   		this.createDate = (java.util.Date)map.get(keys[5]);
   		this.modifiedDate = (java.util.Date)map.get(keys[6]);
   		this.playerId = (int)map.get(keys[7]);
   		this.roleId = (List)map.get(keys[8]);
   		this.reward = (Map)map.get(keys[9]);
   		this.eventLogs = (List)map.get(keys[10]);
   		this.inDating = (boolean)map.get(keys[11]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.cid);
        obj.put(keys[2], this.state);
        obj.put(keys[3], this.finishTime);
        obj.put(keys[4], this.nextRewardTime);
        obj.put(keys[5], this.createDate);
        obj.put(keys[6], this.modifiedDate);
        obj.put(keys[7], this.playerId);
        obj.put(keys[8], toBytes(roleId));
        obj.put(keys[9], toBytes(reward));
        obj.put(keys[10], toBytes(eventLogs));
        obj.put(keys[11], this.inDating);
        return obj;
    }
    
    protected Building createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.cid = obj.getIntValue(keys[1]);
	    this.state = obj.getIntValue(keys[2]);
	    this.finishTime = obj.getDate(keys[3]);
	    this.nextRewardTime = obj.getDate(keys[4]);
	    this.createDate = obj.getDate(keys[5]);
	    this.modifiedDate = obj.getDate(keys[6]);
	    this.playerId = obj.getIntValue(keys[7]);
		this.roleId = (List)forBytesObject(obj.getBytes(keys[8]));
		this.reward = (Map)forBytesObject(obj.getBytes(keys[9]));
		this.eventLogs = (List)forBytesObject(obj.getBytes(keys[10]));
	    this.inDating = obj.getBooleanValue(keys[11]);
        return this;
    }
    
    
    public Building createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.cid = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.state = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.finishTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[3]);
	    this.nextRewardTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[4]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[5]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[6]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[7]);
		this.roleId = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[8]));
		this.reward = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[9]));
		this.eventLogs = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[10]));
	    this.inDating = rs.getBoolean(SOURCE_COLUMN_NAMES[11]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeInt(this.cid);
	    byteBuf.writeInt(this.state);
	    byteBuf.writeDate(this.finishTime);
	    byteBuf.writeDate(this.nextRewardTime);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeObject(this.roleId);
	    byteBuf.writeObject(this.reward);
	    byteBuf.writeObject(this.eventLogs);
	    byteBuf.writeBoolean(this.inDating);
    }
	
	protected Building readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.cid = byteBuf.readInt(null);
	    this.state = byteBuf.readInt(null);
	    this.finishTime = byteBuf.readDate(null);
	    this.nextRewardTime = byteBuf.readDate(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.playerId = byteBuf.readInt(null);
	    this.roleId = (List)byteBuf.readObject();
	    this.reward = (Map)byteBuf.readObject();
	    this.eventLogs = (List)byteBuf.readObject();
	    this.inDating = byteBuf.readBoolean(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Building insert(){
    	return BuildingCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Building update(){
    	return BuildingCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return BuildingCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Building insertAndFlush(){
    	return BuildingCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Building updateAndFlush(){
    	return BuildingCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return BuildingCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Building syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPlayerId(),"_",getCid()).e();
		indexValues[2] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}